﻿@using Gurux.DLMS.AMI.Shared.DTOs
@typeparam TItem
<li class="draggable" draggable="true" @ondragstart="@(() => HandleDragStart(Target))">
    <p class="description">
        @if (DataContent != null && Target != null)
        {
            @(DataContent(Target))
        }
    </p>
</li>

@code {
    [CascadingParameter]
    SelectionContainer<TItem>? Container { get; set; }

    [CascadingParameter]
    SelectionList<TItem>? List { get; set; }

    [Parameter]
    public RenderFragment<TItem>? DataContent { get; set; }

    [Parameter]
    public TItem? Target { get; set; }

    private void HandleDragStart(TItem? target)
    {
        if (Container != null && List != null)
        {
            Container.SourceList = List.Items;
            Container.Item = target;
        }
    }
}